package at.com.vn.chess.applet;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JApplet;
import javax.swing.JFrame;

import at.com.vn.chess.listener.ChessTableListener;

public class ChessFrame extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	ChessTableListener listenerFromChessBoard;
	ChessTableListener callBackToMainApplet;
	
	ChessPanel chessPanel;
	public ChessFrame( String title, String strURL, String userName,
			String roomID, int tableID, JApplet mainApplet ) {
		setLayout( null );
		setTitle( title );	
		chessPanel = new ChessPanel( title, strURL, userName, roomID, tableID, mainApplet );
		add( chessPanel );
				
		this.addWindowListener( new WindowAdapter() {
			public void windowClosing( WindowEvent we ) {
				chessPanel.destroy();
			}
		} );
		
		callBackToMainApplet = new ChessTableListener() {

			@Override
			public void closeClicked() {
				listenerFromChessBoard.closeClicked();				
			}

			@Override
			public void setPlayerClicked( String name, int playerColor,
					String status ) {
				listenerFromChessBoard.setPlayerClicked( name, playerColor, status );				
			}			
		};
		
		chessPanel.setOnCloseListener( callBackToMainApplet );
	}
	
	public void setListener( ChessTableListener listener ) {
		this.listenerFromChessBoard = listener;
	}
}
